package cn.spring.cloud.activity.mybatisps.springbootrabbitmq.utils;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.Map;

@Slf4j
@Component
@RabbitListener(queues = "RabbitConstant.MOBILE_ROUTING_KEY")
public class MobileMessageListener {

    @Autowired
    private smsUtil smsUtil;

    @Value("${aliyun.sms.signName1}")
    private String signName1;

    @Value("${aliyun.sms.templateCode1}")
    private String templateCode1;

    @RabbitHandler
    public void messageHandler(Map<String, String> map) {
        String mobile = map.get("mobile");
        String verifyCode = map.get("verifyCode");
        boolean debugEnabled = log.isDebugEnabled();
        if (debugEnabled) {
            log.debug("手机号:[{}],验证码:[{}]", mobile, verifyCode);
        }
        String templateParam = "{" + "code" + ":" + verifyCode + "}";
        smsUtil.sendSms(mobile, signName1, templateCode1, templateParam);
    }
}
